package com.mikepenz.presenter.imp;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.android.volley.VolleyError;
import com.mikepenz.app.R;
import com.mikepenz.interactor.imp.PayInteractorImp;
import com.mikepenz.presenter.listener.RequestListener;
import com.mikepenz.utils.CookicUntil;
import com.mikepenz.utils.MethodCode;
import com.mikepenz.utils.SystemUtils;
import com.mikepenz.view.PayView;

/**
 * Created by lilongfei on 15/10/29.
 */
public class PayPresenterImp  implements RequestListener<JSONObject>{

    PayView view;
    Context context;
    PayInteractorImp interactor;
    public PayPresenterImp(Context context){
        this.context = context;
        this.view = (PayView) context;
        interactor = new PayInteractorImp(context,this);
    }

    public void getOrderCode(){
        String userId = CookicUntil.getUser().getUserId();
        if (userId == null) {
            view.showError("用户未登录");
            return;
        }
        view.showLoad();
        String currentDate = SystemUtils.getCurrentTime();
        Float money = view.getMoney();
        String cardId = CookicUntil.getCardBean().getCardCode();
        interactor.getOrder(userId,cardId,money,"1",currentDate);
    }

    @Override
    public void Success(String tag, JSONObject result) {
        view.dismissLoad();
        String orderId = result.getJSONObject(MethodCode.OBJECT).getString("orderid");
        view.payDialogShow(orderId);
    }

    @Override
    public void Error(String tag, String error) {
        view.dismissLoad();
        view.showError(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.dismissLoad();
        view.showError(context.getString(R.string.system_error));
    }
}
